package com.clkj.xiuzheng.controller;

import com.clkj.xiuzheng.pojo.IntoStock;
import com.clkj.xiuzheng.pojo.ProductInfo;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.InStockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/inStock")
@Api(value = "/inStock", tags = {"销售入库"})
@CrossOrigin
public class InStockController {

    @Autowired
    private InStockService  inStockService;

    @ApiOperation(value = "添加入库记录")
    @PostMapping("/addInStock")
    public Result addInStock(@RequestBody IntoStock intoStock) {
        try {
            inStockService.addInStock(intoStock);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation(value = "查看入库主表信息")
    @PostMapping("/getInStock")
    public Result getInStock(@RequestParam Integer pageSize,
                             @RequestParam Integer pageNum,
                              Integer companyId) {
        try {
           PageInfo pageInfo = inStockService.getInStock(pageSize,pageNum,companyId);
            return new Result(true, StatusCode.OK,"查询成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }
    @ApiOperation(value = "查看入库分表信息")
    @PostMapping("/getInStockItem")
    public Result getInStockItem(@RequestParam Integer pageSize,
                                 @RequestParam Integer pageNum,
                                 @RequestParam Integer intoId) {
        try {
           PageInfo pageInfo = inStockService.getInStockItem(pageSize,pageNum,intoId);
            return new Result(true, StatusCode.OK,"查询成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }

    @ApiOperation("入库审核")
    @PostMapping("/applyInStockItem")
    public Result applyInStockItem(@RequestParam Integer intoId) {
        try {
            inStockService.applyInStockItem(intoId);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }



    }




}
